import loginView  from '$V/login'
import {
    loginRequest
}from '$a/admin'
export default(req,res)=>{
    res.render(loginView())
    
    //获取元素
    document.loginForm.loginBtn.onclick = async function(e){
        e.preventDefault()
        //获取输入的用户名和密码
        const adminNameValue =document.loginForm.adminName.value;
        const passwordValue = document.loginForm.passWord.value;
        
        try{
            const loginResult = await loginRequest({
                adminName:adminNameValue,
                passWord:passwordValue
            })

            //登录成功可以拿到token,将token放入localStoeage中 然后跳转页面
            localStorage.setItem('user_token',loginResult.token)
            router.go('/adv/advList')
        }catch(e){
            alert('登录异常'+e.message)

        }
    }
}